package com.ssy.lingxi.platform.template.service.controller.adorn;

import com.ssy.lingxi.common.constant.basic.UserLoginSourceEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.template.service.entity.adorn.Advert;
import com.ssy.lingxi.platform.template.service.model.bo.ColumnBO;
import com.ssy.lingxi.platform.template.service.model.dto.adorn.*;
import com.ssy.lingxi.platform.template.service.model.dto.common.MemberIdAndRoleIdDTO;
import com.ssy.lingxi.platform.template.service.model.dto.common.TemplateIdDTO;
import com.ssy.lingxi.platform.template.service.model.dto.web.RecommendDTO;
import com.ssy.lingxi.platform.template.service.model.vo.adorn.*;
import com.ssy.lingxi.platform.template.service.service.adorn.WebSelfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 模板装修 - WEB自营装修
 * @author fhj
 * @version 2.0.0
 * @date 2021/09/28
 */
@Api(tags = "模板装修 - WEB自营装修")
@RestController
@RequestMapping("/template/adorn/webSelf")
public class WebSelfController extends BaseController {

    @Resource
    private WebSelfService webSelfService;

    @ApiOperation(value = "获取所有一级会员品类")
    @GetMapping("/findAllFirstCategory")
    public Wrapper<List<CategoryVO>> findAllFirstCategory(@Valid MemberIdAndRoleIdDTO dto) {
        return webSelfService.findAllFirstCategory(dto, getHeadersShopId());
    }

    @ApiOperation(value = "会员品类的装修内容")
    @GetMapping("/memberCategoryAdorn")
    public Wrapper<CategoryAdornVO> memberCategoryAdorn(@Valid CategoryAdornDTO dto) {
        return webSelfService.memberCategoryAdorn(dto, isLogin() && getSysUser().getLoginSource().equals(UserLoginSourceEnum.BUSINESS_WEB.getCode()) ? getSysUser() : null);
    }

    @ApiOperation(value = "根据类型获取广告")
    @GetMapping("/findAdvertsByType")
    public Wrapper<List<Advert>> findAdvertsByType(@Valid AdvertDTO dto) {
        return webSelfService.findAdvertsByType(dto);
    }

    @ApiOperation(value = "获取导航栏")
    @GetMapping("/findColumn")
    public Wrapper<List<ColumnBO>> findColumn(@Valid TemplateIdDTO dto, Long memberId, Long roleId) {
        return webSelfService.findColumn(dto, memberId, roleId);
    }

    @ApiOperation(value = "获取商品列表")
    @GetMapping("/findGoodsList")
    public Wrapper<PageData<GoodsVO>> findGoodsList(@Valid RecommendDTO dto) {
        return webSelfService.findGoodsList(dto, getSysUser());
    }

    @ApiOperation(value = "获取品类列表")
    @GetMapping("/findCategoryList")
    public Wrapper<CategoryAdornVO> findCategoryList(@Valid RecommendDTO dto) {
        return webSelfService.findCategoryList(dto, getSysUser());
    }

    @ApiOperation(value = "获取品牌列表（下拉框）")
    @GetMapping("/findBrandList")
    public Wrapper<PageData<BrandVO>> findBrandList(@Valid RecommendDTO dto) {
        return webSelfService.findBrandList(dto, getSysUser());
    }

    @ApiOperation(value = "保存广告")
    @PostMapping("/saveAdvert")
    public Wrapper<Void> saveAdvert(@RequestBody @Valid SaveAdvertDTO dto) {
        return webSelfService.saveAdvert(dto, getSysUser());
    }

    @ApiOperation(value = "保存导航栏")
    @PostMapping("/saveColumn")
    public Wrapper<Void> saveColumn(@RequestBody @Valid SaveColumnDTO dto) {
        return webSelfService.saveColumn(dto, getSysUser());
    }

    @ApiOperation(value = "保存商品")
    @PostMapping("/saveGoods")
    public Wrapper<Void> saveGoods(@RequestBody @Valid SaveTemplateAdornDTO dto) {
        return webSelfService.saveGoods(dto, getSysUser());
    }

    @ApiOperation(value = "保存品类")
    @PostMapping("/saveCategory")
    public Wrapper<Void> saveCategory(@RequestBody @Valid SaveTemplateAdornDTO dto) {
        return webSelfService.saveCategory(dto, getSysUser());
    }
}
